#!/usr/bin/env python 
# -*- coding: utf-8 -*-
# @Time    : 2023/12/14 17:39
# @Author  : WJQ
# @Site    : 
# @File    : change_user_agent.py
# @Software: PyCharm
from mitmproxy import http

def request(flow: http.HTTPFlow) -> None:
    # 检查请求的 URL 是否匹配
    if "https://m.baidu.com/sf/vsearch?" in flow.request.pretty_url:
        # 修改 User-Agent
        flow.request.headers["User-Agent"] = "Mozilla/5.0 (Linux; Android 12; AOSP on crosshatch Build/SP1A.210812.016.C2; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/91.0.4472.114 Mobile Safari/537.36 swan/2.15.0 swan-baiduboxapp/11.19.0.11 baiduboxapp/11.19.0.11 (Baidu; P1 12)"
